# Contributor: Celeste <cielesti@protonmail.com>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=azorius
pkgver=0.3.2
pkgrel=0
pkgdesc="Social link aggregator and comment forum with ActivityPub"
url="https://azorius.net/"
arch="all"
license="ISC"
makedepends="go sqlite-dev"
install="$pkgname.pre-install"
pkgusers="azorius"
pkggroups="azorius"
subpackages="$pkgname-doc $pkgname-openrc"
source="https://humungus.tedunangst.com/r/azorius/d/azorius-$pkgver.tgz
	azorius.initd
	azorius.confd
	"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	make
}

check() {
	./azorius version

	go test -v ./...
}

package() {
	install -Dm755 azorius -t "$pkgdir"/usr/bin/
	install -dm750 -o azorius -g azorius "$pkgdir"/var/lib/azorius

	install -dm755 "$pkgdir"/usr/share/webapps/azorius
	install -Dm644 docs/*.html -t "$pkgdir"/usr/share/webapps/azorius/docs/
	install -Dm644 views/* -t "$pkgdir"/usr/share/webapps/azorius/views/

	install -Dm644 LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
	local man sec fname; for man in \
		docs/*.1 \
		docs/*.7 \
		docs/*.8
	do
		fname="$(basename $man)"
		sec="${fname##*.}"

		case "$fname" in
		azorius*)
			install -Dm644 $man \
				"$pkgdir"/usr/share/man/man$sec/$fname
			;;
		*)
			install -Dm644 $man \
				"$pkgdir"/usr/share/man/man$sec/azorius-$fname
			;;
		esac
	done

	install -Dm755 "$srcdir"/azorius.initd "$pkgdir"/etc/init.d/azorius
	install -Dm644 "$srcdir"/azorius.confd "$pkgdir"/etc/conf.d/azorius
}

sha512sums="
aaf1b824b67a70476726002a51cbf59bd2a36d3ac2680703c6f4b8e79b82f9de1cc7bdc2389be8aad623901f274ca6b0f0b4f8fb1c945f678e1d197ee5e76a5b  azorius-0.3.2.tgz
aa8641ef0a4c6b27d4ac21f2dd974dcd090f5867ee314c4322f39284a8e80b430f522fcb75c51db8dd0c00791a2c76652827eda091183ee57a2b3f8c97d8b88c  azorius.initd
fb522c19c7debd64c57087d5a77f03f0418e0eb929c570cbb0cb5fb36a97e63b09b34bc4137aff36fe625fb3ced8b1d16529a8ba1af79cffa67a9033acfa7a1d  azorius.confd
"
